/**
 * This file is Copyright © 2008 Software Craftsmen Limited. All Rights Reserved.
 */
package com.softwarecraftsmen.collections;

import org.jetbrains.annotations.NotNull;
import static com.softwarecraftsmen.functors.Boolean.fromLegacyBoolean;

public class LegacyKeyWrapper<K> implements Key
{
	public final K value;

	public LegacyKeyWrapper(final @NotNull K value)
	{
		this.value = value;
	}

	public com.softwarecraftsmen.functors.Boolean isEqualTo(final @NotNull Key key)
	{
		return fromLegacyBoolean(key instanceof LegacyKeyWrapper).and(fromLegacyBoolean(value.equals(((LegacyKeyWrapper) key).value)));
	}

	public int computeHashCode()
	{
		return value.hashCode();
	}

	public boolean equals(final Object o)
	{
		if (this == o)
		{
			return true;
		}
		if (o == null || getClass() != o.getClass())
		{
			return false;
		}

		final LegacyKeyWrapper that = (LegacyKeyWrapper) o;

		return value.equals(that.value);
	}

	public int hashCode()
	{
		return value.hashCode();
	}

	@NotNull
	public static <K> LegacyKeyWrapper<K> wrap(final @NotNull K value)
	{
		return new LegacyKeyWrapper<K>(value);
	}

}
